<template>
  <div>
      <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>资源管理</el-breadcrumb-item>
      <el-breadcrumb-item>油料管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
        <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入油站名" v-model="queryInfo.query" clearable @clear="getOilList">
            <el-button slot="append" icon="el-icon-search" @click="getOilList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 用户列表区域 -->
      <el-table :data="oilList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="油料编号" prop="pid"></el-table-column>
        <el-table-column label="油料名称" prop="pname"></el-table-column>
        <el-table-column label="油站" prop="homename"></el-table-column>
        <el-table-column label="库存/升" prop="number"></el-table-column>
        <el-table-column label="地址" prop="address"></el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" 
      :current-page="queryInfo.pagenum" :page-sizes="[1, 2, 5, 10]" :page-size="queryInfo.pagesize" 
      layout="total, sizes, prev, pager, next, jumper" :total="totalnum">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: '',
  data () {
    return {
        // 获取油料列表的参数对象
        queryInfo: {
            query: '',
            // 当前的页数
            pagenum: 1,
            // 当前每页显示多少条数据
            pagesize: 5
        },
        oilList:[],
        totalnum: 4
    }
  },
  created() {
      this.getOilList()
  },
  methods: {
      async getOilList() {
        const {data: res} = await this.$http.get('sysservice/produce/findAll', {
          params: this.queryInfo
        })
        if(res.code!=2000) {return this.$message.error('获取用户列表失败！')}
        this.oilList = res.data.rows
        this.totalnum = res.data.total
        //console.log(this.oilList);
        
      },
     // 监听 pagesize 改变的事件
     handleSizeChange(newSize) {
          //console.log(newSize)
          this.queryInfo.pagesize = newSize
          this.getOilList()
     },
     // 监听 页码值 改变的事件
     handleCurrentChange(newPage) {
          console.log(newPage)
          this.queryInfo.pagenum = newPage
          this.getOilList()
     }


  }
}
</script>

<style scoped lang=scss>

</style>